package com.foreknow.demo2;

import java.util.Scanner;

public class Example1 {
    public static void main(String[] args) {
        int choice;
        String answer = "y";
        String name = "";
        int password = 0;
        do {
            System.out.println("**************Menu*******************");
            System.out.println("         1. 注册");
            System.out.println("         2. 登录");
            System.out.println("         3. 抽奖");
            System.out.println("************************************");
            Scanner input = new Scanner(System.in);
            System.out.println("请选择菜单：");
            choice = input.nextInt();
            switch (choice){
                case 1:
                    System.out.println("系统：注册");
                    int card = (int) (Math.random() * (9999 - 1000 + 1)) + 1000;
                    System.out.println("请填写注册信息：");
                    System.out.println("用户名：");
                    name = input.next();
                    System.out.println("六位密码：");
                    password = input.nextInt();
                    System.out.println("注册成功，请记好您的会员卡号");
                    System.out.println("用户名\t密码\t会员卡号\n" + name + "\t   " + password + "\t" + card);
                    break;
                case 2:
                    System.out.println("系统：登录");
                    int i = 0;
                    System.out.println("请输入用户名：");
                    String name1 = input.next();
                    if (name1.equals(name)) {
                        while (i<3){
                            System.out.println("请输入密码");
                            int password1 = input.nextInt();
                            if (password1 == password) {
                                System.out.println("登录成功：" + name);
                                break;
                            }else {
                                System.out.println("密码错误！");
                                System.out.println("还有"+(2-i)+"次输入机会");
                                i++;
                            }
                        }
                    }else {
                            System.out.println("用户尚未注册！");

                        }
                    break;
                case 3:
                    System.out.println("系统：抽奖");
                    break;
                default:
                    System.out.println("输入错误，请重新输入！");
            }
            System.out.println("是否继续(y/n):");
            answer = input.next();
        }while ("y".equals(answer));
        System.out.println("退出系统，谢谢使用！");
    }

}

